<?php 
/**
*市场总监
*/
require("./include/init.php");
//市场总监只是北区北京这一个公司的
//市场总监中的数据概况是从area表中进行查取获得的
$mysql=mysql::getIns();

$address=$_REQUEST['address'];

date_default_timezone_set('Asia/Shanghai');


$maxtime=time();
$mintime=$maxtime-10*60;
// echo $maxtime . '<br />';
// echo $mintime;
$sql="select count(*) from alldev where timestamp > $mintime and timestamp < $maxtime and shop='". $address ."'";
$allnow=$mysql->getOne($sql);
// echo $allnow;
// print_r($allnow);
// exit;


//统计当天累计人数数
$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
$end = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
$sql="select count(*) from alldev where timestamp > $start and timestamp < $end and shop='" . $address . "'";
$allday=$mysql->getOne($sql);

//首次今天首次进店人数,通过字段visittimes为1来进行判断
$sql="select count(*) from alldev where visittimes=1 and timestamp > $mintime and timestamp < $maxtime and shop='".$address ."'";
$firstlogin=$mysql->getOne($sql);

//统计当前销售区
$sql="select count(*) from alldev where timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."' and area in ('展厅区','销售区','精品区')";
$sale=$mysql->getOne($sql);
// echo $sale;
// print_r($sale);
// exit;

//统计当前售后区
$service=$allnow-$sale;


//今天多次进店人数
$sql="select count(*) from alldev where visittimes <> 1 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$secondlogin=$mysql->getOne($sql);

//统计登陆人数
$sql="select count(*) from alldev where isOL=1 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$login=$mysql->getOne($sql);
// echo $login;

//统计未登陆人数
$sql="select count(*) from alldev where isOL=2 and timestamp > $mintime and timestamp < $maxtime and shop='" . $address ."'";
$nolog=$mysql->getOne($sql);
// echo $nolog;

//统计历史进店人数
$sql="select count(*) from alldev where shop='". $address ."'";
$history=$mysql->getOne($sql);

$data=include('./include/history.inc.php');
// print_r($data);
$b=$data["$address"];
$history+=$b;





//根据address取出本店的数据来

// $sql="select count(*) from alldev where isOL=1 and timestamp > $mintime and timestamp < $maxtime and shop='". $address ."'";

//获取今天凌晨的时间戳
$today = strtotime(date('Y-m-d', time()));

//获取早晨9点的时间戳
$now9=$today+9*60*60;
// echo date('Y-m-d H:i:s',$now9);

//获取今天早晨10点的时间戳
$now10=$today+10*60*60;
$now11=$today+11*60*60;
$now12=$today+12*60*60;
$now13=$today+13*60*60;
$now14=$today+14*60*60;
$now15=$today+15*60*60;
$now16=$today+16*60*60;
$now17=$today+17*60*60;
$now18=$today+18*60*60;
$now19=$today+19*60*60;

//9点时的人数为
$sql="select count(*) from alldev where timestamp >= $now9 and timestamp < $now10 and shop='". $address ."'";
$p9=$mysql->getOne($sql);
// echo $p9;

//10点时的人数
$sql="select count(*) from alldev where timestamp >= $now10 and timestamp < $now11 and shop='". $address ."'";
$p10=$mysql->getOne($sql);

//11点时的人数
$sql="select count(*) from alldev where timestamp >= $now11 and timestamp < $now12 and shop='". $address ."'";
$p11=$mysql->getOne($sql);


//12点时的人数
$sql="select count(*) from alldev where timestamp >= $now12 and timestamp < $now13 and shop='". $address ."'";
$p12=$mysql->getOne($sql);


//13点时的人数
$sql="select count(*) from alldev where timestamp >= $now13 and timestamp < $now14 and shop='". $address ."'";
$p13=$mysql->getOne($sql);


//14点时的人数
$sql="select count(*) from alldev where timestamp >= $now14 and timestamp < $now15 and shop='". $address ."'";
$p14=$mysql->getOne($sql);


//15点时的人数
$sql="select count(*) from alldev where timestamp >= $now15 and timestamp < $now16 and shop='". $address ."'";
$p15=$mysql->getOne($sql);


//16点时的人数
$sql="select count(*) from alldev where timestamp >= $now16 and timestamp < $now17 and shop='". $address ."'";
$p16=$mysql->getOne($sql);

//17点时的人数
$sql="select count(*) from alldev where timestamp >= $now17 and timestamp < $now18 and shop='". $address ."'";
$p17=$mysql->getOne($sql);


//18点时的人数
$sql="select count(*) from alldev where timestamp >= $now18 and timestamp < $now19 and shop='". $address ."'";
$p18=$mysql->getOne($sql);
// exit;


//昨天9点时间戳
$yesd9=$today+9*60*60-24*60*60;
$yesd10=$today+10*60*60-24*60*60;
$yesd11=$today+11*60*60-24*60*60;
$yesd12=$today+12*60*60-24*60*60;
$yesd13=$today+13*60*60-24*60*60;
$yesd14=$today+14*60*60-24*60*60;
$yesd15=$today+15*60*60-24*60*60;
$yesd16=$today+16*60*60-24*60*60;
$yesd17=$today+17*60*60-24*60*60;
$yesd18=$today+18*60*60-24*60*60;
$yesd19=$today+19*60*60-24*60*60;


//昨天9点时的人数为
$sql="select count(*) from alldev where timestamp >= $yesd9 and timestamp < $yesd10 and shop='". $address ."'";
$b9=$mysql->getOne($sql);
// echo $p9;

//昨天10点时的人数
$sql="select count(*) from alldev where timestamp >= $yesd10 and timestamp < $yesd11 and shop='". $address ."'";
$b10=$mysql->getOne($sql);

//昨天11点时的人数
$sql="select count(*) from alldev where timestamp >= $yesd11 and timestamp < $yesd12 and shop='". $address ."'";
$b11=$mysql->getOne($sql);


//昨天12点时的人数
$sql="select count(*) from alldev where timestamp >= $yesd12 and timestamp < $yesd13 and shop='". $address ."'";
$b12=$mysql->getOne($sql);


//昨天13点时的人数
$sql="select count(*) from alldev where timestamp >= $yesd13 and timestamp < $yesd14 and shop='". $address ."'";
$b13=$mysql->getOne($sql);


//昨天14点时的人数
$sql="select count(*) from alldev where timestamp >= $yesd14 and timestamp < $yesd15 and shop='". $address ."'";
$b14=$mysql->getOne($sql);


//昨天15点时的人数
$sql="select count(*) from alldev where timestamp >= $yesd15 and timestamp < $yesd16 and shop='". $address ."'";
$b15=$mysql->getOne($sql);


//昨天16点时的人数
$sql="select count(*) from alldev where timestamp >= $yesd16 and timestamp < $yesd17 and shop='". $address ."'";
$b16=$mysql->getOne($sql);

//昨天17点时的人数
$sql="select count(*) from alldev where timestamp >= $yesd17 and timestamp < $yesd18 and shop='". $address ."'";
$b17=$mysql->getOne($sql);


//昨天18点时的人数
$sql="select count(*) from alldev where timestamp >= $yesd18 and timestamp < $yesd19 and shop='". $address ."'";
$b18=$mysql->getOne($sql);
// echo $b18;


//获取上周周一的时间
$one=strtotime('-2 monday', time());
// echo $one . '<br />';
// echo date('Y-m-d H:i:s',$one);
//获取上周周二时间
$two=strtotime('-2 monday', time())+24*3600*1;

//获取上周周三时间
$three=strtotime('-2 monday', time())+24*3600*2;

//获取上周周四时间
$four=strtotime('-2 monday', time())+24*3600*3;

//获取上周周五时间
$five=strtotime('-2 monday', time())+24*3600*4;

//获取上周周六时间
$six=strtotime('-2 monday', time())+24*3600*5;

//获取上周周日时间
$seven=strtotime('-2 monday', time())+24*3600*6;
// echo date('Y-m-d H:i:s',$seven);

//获取本周周一
$nowone=strtotime('-2 monday', time())+24*3600*7;
// echo date('Y-m-d H:i:s',$nowone);

//获取上周周一的人数
$sql="select count(*) from alldev where timestamp >= $one and timestamp < $two and shop='". $address ."'";
$onep=$mysql->getOne($sql);
// echo $one;
// exit;

//获取上周周二的人数
$sql="select count(*) from alldev where timestamp >= $two and timestamp < $three and shop='". $address ."'";
$twop=$mysql->getOne($sql);

//获取上周周三的人数
$sql="select count(*) from alldev where timestamp >= $three and timestamp < $four and shop='". $address ."'";
$threep=$mysql->getOne($sql);


//获取上周周四的人数
$sql="select count(*) from alldev where timestamp >= $four and timestamp < $five and shop='". $address ."'";
$fourp=$mysql->getOne($sql);


//获取上周周五的人数
$sql="select count(*) from alldev where timestamp >= $five and timestamp < $six and shop='". $address ."'";
$fivep=$mysql->getOne($sql);

//获取上周周六的人数
$sql="select count(*) from alldev where timestamp >= $six and timestamp < $seven and shop='". $address ."'";
$sixp=$mysql->getOne($sql);

//获取上周周日的人数
$sql="select count(*) from alldev where timestamp >= $seven and timestamp < $nowone and shop='". $address ."'";
$sevenp=$mysql->getOne($sql);
// echo $sevenp;
// exit;


//获取上个月第一天时间
$first =mktime(0,0,0,date('m',time())-1,1,date('Y',time()));
// echo date('Y-m-d H:i:s',$first);
//获取上个月第二周时间
$second=$first+7*24*3600;
// echo date('Y-m-d H:i:s',$second);

//获取上个月第三周时间
$third=$second+7*24*3600;

//获取上个月第四周时间
$fourth=$third+7*24*3600;
// echo date('Y-m-d H:i:s',$fourth);

//获取上个月第五周时间
$fifth =mktime(0,0,0,date('m',time()),1,date('Y',time()));
// $fifth=$fourth+7*24*3600;
// echo date('Y-m-d H:i:s',$fifth);
// exit;


//获取上个月第一周的人数
$sql="select count(*) from alldev where timestamp >= $first and timestamp < $second and shop='". $address ."'";
$firstp=$mysql->getOne($sql);
// echo $one;
// exit;

//获取上月第二周的人数
$sql="select count(*) from alldev where timestamp >= $second and timestamp < $third and shop='". $address ."'";
$secondp=$mysql->getOne($sql);

//获取上月第三周的人数
$sql="select count(*) from alldev where timestamp >= $third and timestamp < $fourth and shop='". $address ."'";
$thirdp=$mysql->getOne($sql);


//获取上月第四周的人数
$sql="select count(*) from alldev where timestamp >= $fourth and timestamp < $fifth and shop='". $address ."'";
$fourthp=$mysql->getOne($sql);


//获取第一季度开始时间戳
$firstmonth =mktime(0,0,0,1,1,date('Y',time()));

//获取第二季度开始时间
$secondmonth =mktime(0,0,0,4,1,date('Y',time()));
// echo date('Y-m-d H:i:s',$secondmonth);

//获取第三季度开始时间
$thirdmonth =mktime(0,0,0,7,1,date('Y',time()));
// echo date('Y-m-d H:i:s',$thirdmonth);

//获取第四季度开始时间
$fourthmonth =mktime(0,0,0,10,1,date('Y',time()));
// echo date('Y-m-d H:i:s',$fourthmonth);

//获取明年第一季度开始时间
$firstmonths =mktime(0,0,0,1,1,date('Y',time())+1);
// echo date('Y-m-d H:i:s',$firstmonths);



//获取第一季度的人数
$sql="select count(*) from alldev where timestamp >= $firstmonth and timestamp < $secondmonth and shop='". $address ."'";
$firstmonth=$mysql->getOne($sql);
// echo $one;
// exit;

//获取第二季度的人数
$sql="select count(*) from alldev where timestamp >= $secondmonth and timestamp < $thirdmonth and shop='". $address ."'";
$secondmonth=$mysql->getOne($sql);

//获取第三季度的人数
$sql="select count(*) from alldev where timestamp >= $thirdmonth and timestamp < $fourthmonth and shop='". $address ."'";
$thirdmonth=$mysql->getOne($sql);
// echo $thirdmonth;
// exit;


//获取第四季度的人数
$sql="select count(*) from alldev where timestamp >= $fourthmonth and timestamp < $firstmonths and shop='". $address ."'";
$fourthmonth=$mysql->getOne($sql);

// echo $fourthmonth;
// exit;






/**********************************************************************

							历史集客环比


**********************************************************************/


//统计集客比今天人数
$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
$end = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
$sql="select count(*) from alldev where timestamp > $start and timestamp < $end and shop='". $address ."'";
$nowjk=$mysql->getOne($sql);


//统计昨天集客比
$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t)-1,date("Y",$t));
$end = mktime(23,59,59,date("m",$t),date("d",$t)-1,date("Y",$t));
$sql="select count(*) from alldev where timestamp > $start and timestamp < $end and shop='". $address ."'";
$yesdjk=$mysql->getOne($sql);
// echo $yesdjk;
// exit;



//获取本周周一的时间
$one=strtotime('-1 monday', time());
// echo $one . '<br />';
// echo date('Y-m-d H:i:s',$one);
// exit;
//获取本周周二时间
$two=strtotime('-1 monday', time())+24*3600*1;

//获取本周周三时间
$three=strtotime('-1 monday', time())+24*3600*2;

//获取本周周四时间
$four=strtotime('-1 monday', time())+24*3600*3;

//获取本周周五时间
$five=strtotime('-1 monday', time())+24*3600*4;

//获取本周周六时间
$six=strtotime('-1 monday', time())+24*3600*5;

//获取本周周日时间
$seven=strtotime('-1 monday', time())+24*3600*6;
// echo date('Y-m-d H:i:s',$seven);

//获取本周周一
$nowone=strtotime('-1 monday', time())+24*3600*7;
// echo date('Y-m-d H:i:s',$nowone);


//统计本周周一集客比
$sql="select count(*) from alldev where timestamp >= $one and timestamp < $two and shop='". $address ."'";
$onejk=$mysql->getOne($sql);
//统计本周周二集客比
$sql="select count(*) from alldev where timestamp >= $two and timestamp < $three and shop='". $address ."'";
$twojk=$mysql->getOne($sql);
//统计本周周三集客比
$sql="select count(*) from alldev where timestamp >= $three and timestamp < $four and shop='". $address ."'";
$threejk=$mysql->getOne($sql);
//统计本周周四集客比
$sql="select count(*) from alldev where timestamp >= $four and timestamp < $five and shop='". $address ."'";
$fourjk=$mysql->getOne($sql);
//统计本周周五集客比
$sql="select count(*) from alldev where timestamp >= $five and timestamp < $six and shop='". $address ."'";
$fivejk=$mysql->getOne($sql);

//统计本周周六集客比
$sql="select count(*) from alldev where timestamp >= $six and timestamp < $seven and shop='". $address ."'";
$sixjk=$mysql->getOne($sql);
// echo $sixjk;
// exit;
//统计本周周日集客比
$sql="select count(*) from alldev where timestamp >= $seven and timestamp < $nowone and shop='". $address ."'";
$sevenjk=$mysql->getOne($sql);




//统计本月人数

/**************************
获取本月第一个周一的时间

**********************/
$year=date('Y',time());
$month=date('m',time());
$base_time = strtotime ( "{$year}-{$month}-01" );
$base_w = date ( "w", $base_time );

if($base_w == '1'){
  //刚好是星期一
  $first = $base_time;
}else{
  //不是星期一
  //找到上个星期天是几月几号
  $last_sun = date ( "Y-m-d", strtotime("-$base_w day", $base_time));
  //在上个星期天的基础上 加8天
  $first = strtotime ( "+8 day", strtotime ( $last_sun ) );
}
//第二个周一的时间
$second=$first+7*24*3600;
// echo date('Y-m-d H:i:s',$second);
// exit;
//第三个时间戳
$third=$second+7*24*3600;
// echo date('Y-m-d H:i:s',$third);
// exit;
//第四个时间戳
$fourth=$third+7*24*3600;
// echo date('Y-m-d H:i:s',$fourth);
// exit;
//下周一时间戳
$fifth=$fourth+7*24*3600;
// echo date('Y-m-d H:i:s',$third);
// exit;





//获取这个月第一周的人数
$sql="select count(*) from alldev where timestamp >= $first and timestamp < $second and shop='". $address ."'";
$firstjk=$mysql->getOne($sql);
// echo $one;
// exit;

//获取这个月第二周的人数
$sql="select count(*) from alldev where timestamp >= $second and timestamp < $third and shop='". $address ."'";
$secondjk=$mysql->getOne($sql);
// echo $secondjk;
// exit;
$bak=$secondjk;
//获取这个月第三周的人数
$sql="select count(*) from alldev where timestamp >= $third and timestamp < $fourth and shop='". $address ."'";
$thirdjk=$mysql->getOne($sql);
// echo $thirdjk;
// exit;

//获取这个月第四周的人数
$sql="select count(*) from alldev where timestamp >= $fourth and timestamp < $fifth and shop='". $address ."'";
$fourthjk=$mysql->getOne($sql);



/*******

年集客比用上述计算的即可,和上边中的年中的一样

******/


/*************************************************



同区集客对比



**************************************************/


//今天集客为今天累计人数 $allday

//全区集客平均值   因为字段中没有区域,暂时只有一个店,平均值与今天的一样



if($address=='成都新元素雅麓汽车销售服务有限公司'||$address=='云南驰泰汽车销售服务有限公司'||
	$address=='宁夏奥立升汽车销售服务有限公司'||$address=='陕西奥诚汽车销售服务有限公司'){



	//获取本周周一的时间
	$one=strtotime('-1 monday', time());
	// echo $one . '<br />';
	// echo date('Y-m-d H:i:s',$one);
	// exit;

	//获取下周周一
	$nowone=strtotime('-1 monday', time())+24*3600*7;
	// echo date('Y-m-d H:i:s',$nowone);
	// exit;

	//本周的集客比
	$sql="select count(*) from alldev where timestamp > $one and timestamp < $end and shop='成都新元素雅麓汽车销售服务有限公司' or shop='云南驰泰汽车销售服务有限公司' 
	or shop='宁夏奥立升汽车销售服务有限公司' or shop='陕西奥诚汽车销售服务有限公司'";
	$week=$mysql->getOne($sql);
	// echo $week;
	// exit;

	//区域平均值于此一样


	//本月的集客比



	//获取这个个月第一天时间
	$first =mktime(0,0,0,date('m',time()),1,date('Y',time()));
	// echo date('Y-m-d H:i:s',$first);
	// exit;


	//获取这个月第五周时间
	$fifth =mktime(0,0,0,date('m',time())+1,1,date('Y',time()));
	// echo date('Y-m-d H:i:s',$fifth);
	// exit;

	$sql="select count(*) from alldev where timestamp > $first and timestamp < $fifth and shop='成都新元素雅麓汽车销售服务有限公司' or shop='云南驰泰汽车销售服务有限公司' 
	or shop='宁夏奥立升汽车销售服务有限公司' or shop='陕西奥诚汽车销售服务有限公司'";
	$month=$mysql->getOne($sql);
	// echo $month;
	// exit;

	//本月平均值于此一样

	//今年第一天和最后一天时间
	$year=date("Y",time());
	$firsttime=$year."-01-01";
	// echo $first;
	$firsttime=strtotime($firsttime);
	// echo date('Y-m-d H:i:s',$first);
	// exit;
	$years=$year+1;
	$endtime=$years."-01-01";
	$endtime=strtotime($endtime);
	// echo date('Y-m-d H:i:s',$end);
	// exit;

	$sql="select count(*) from alldev where timestamp > $firsttime and timestamp < $endtime and shop='成都新元素雅麓汽车销售服务有限公司' or shop='云南驰泰汽车销售服务有限公司' 
	or shop='宁夏奥立升汽车销售服务有限公司' or shop='陕西奥诚汽车销售服务有限公司'";
	$years=$mysql->getOne($sql);
	//今天平均值
	$avgallday=ceil($allday/4);
	//周平均值
	$avgweek=ceil($week/4);
	//月平均值
	$avgmonth=ceil($month/4);
	//年平均值
	$avgyears=ceil($years/4);
	//获取本周周一的时间
	$one=strtotime('-1 monday', time());
	// echo $one . '<br />';
	// echo date('Y-m-d H:i:s',$one);
	// exit;

	//获取下周周一
	$nowone=strtotime('-1 monday', time())+24*3600*7;
	// echo date('Y-m-d H:i:s',$nowone);
	// exit;

	//本周的集客比
	$sql="select count(*) from alldev where timestamp > $one and timestamp < $end and shop='" . $address . "'";
	$week=$mysql->getOne($sql);

	// echo $week;
	// exit;
	// echo $week;
	// exit;

	//区域平均值于此一样


	//本月的集客比



	//获取这个个月第一天时间
	$first =mktime(0,0,0,date('m',time()),1,date('Y',time()));
	// echo date('Y-m-d H:i:s',$first);
	// exit;


	//获取这个月第五周时间
	$fifth =mktime(0,0,0,date('m',time())+1,1,date('Y',time()));
	// echo date('Y-m-d H:i:s',$fifth);
	// exit;

	$sql="select count(*) from alldev where timestamp > $first and timestamp < $fifth and shop='" . $address . "'";
	$month=$mysql->getOne($sql);
	// echo $month;
	// exit;

	//本月平均值于此一样

	//今年第一天和最后一天时间
	$year=date("Y",time());
	$firsttime=$year."-01-01";
	// echo $first;
	$firsttime=strtotime($firsttime);
	// echo date('Y-m-d H:i:s',$first);
	// exit;
	$years=$year+1;
	$endtime=$years."-01-01";
	$endtime=strtotime($endtime);
	// echo date('Y-m-d H:i:s',$end);
	// exit;

	$sql="select count(*) from alldev where timestamp > $firsttime and timestamp < $endtime and shop='" . $address . "'";
	$years=$mysql->getOne($sql);
}else{


//获取本周周一的时间
$one=strtotime('-1 monday', time());
// echo $one . '<br />';
// echo date('Y-m-d H:i:s',$one);
// exit;

//获取下周周一
$nowone=strtotime('-1 monday', time())+24*3600*7;
// echo date('Y-m-d H:i:s',$nowone);
// exit;

//本周的集客比
$sql="select count(*) from alldev where timestamp > $one and timestamp < $end and shop='" . $address . "'";
$week=$mysql->getOne($sql);

// echo $week;
// exit;
// echo $week;
// exit;

//区域平均值于此一样


//本月的集客比



//获取这个个月第一天时间
$first =mktime(0,0,0,date('m',time()),1,date('Y',time()));
// echo date('Y-m-d H:i:s',$first);
// exit;


//获取这个月第五周时间
$fifth =mktime(0,0,0,date('m',time())+1,1,date('Y',time()));
// echo date('Y-m-d H:i:s',$fifth);
// exit;

$sql="select count(*) from alldev where timestamp > $first and timestamp < $fifth and shop='" . $address . "'";
$month=$mysql->getOne($sql);
// echo $month;
// exit;

//本月平均值于此一样

//今年第一天和最后一天时间
$year=date("Y",time());
$firsttime=$year."-01-01";
// echo $first;
$firsttime=strtotime($firsttime);
// echo date('Y-m-d H:i:s',$first);
// exit;
$years=$year+1;
$endtime=$years."-01-01";
$endtime=strtotime($endtime);
// echo date('Y-m-d H:i:s',$end);
// exit;

$sql="select count(*) from alldev where timestamp > $firsttime and timestamp < $endtime and shop='" . $address . "'";
$years=$mysql->getOne($sql);
// echo $years;
// exit;

$avgallday=$allday;
	//周平均值
	$avgweek=$week;
	//月平均值
	$avgmonth=$month;
	//年平均值
	$avgyears=$years;
}

/********************************************************************

全国集客对比


***********************************************************************/

//本店值月上述的一样

//全国今天的值
$sql="select count(*) from alldev where timestamp > $start and timestamp < $end and shop <> 'Audi City BeiJing'";
$alldaycountry=$mysql->getOne($sql);
// echo $alldaycountry;
// exit;
$sql="select shop from alldev group by shop";
$num=$mysql->getAll($sql);
// print_r($num);
$num=count($num)-1;
// echo $num;
// exit;
//全国今天的平均值
$daycountry=ceil($alldaycountry/$num);
// echo $daycountry;
// exit;
//全国本周的值

$sql="select count(*) from alldev where timestamp > $one and timestamp < $end and shop <> 'Audi City BeiJing'";
$allweekcountry=$mysql->getOne($sql);
//全国本周的平均值
$weekcountry=ceil($allweekcountry/$num);


//全国本月的平均值
$sql="select count(*) from alldev where timestamp > $first and timestamp < $fifth and shop <> 'Audi City BeiJing'";
$allmonthcountry=$mysql->getOne($sql);
$monthcountry=ceil($allmonthcountry/$num);


//全国本年的值
$sql="select count(*) from alldev where timestamp > $firsttime and timestamp < $endtime and shop <> 'Audi City BeiJing'";
$allyearscountry=$mysql->getOne($sql);
$yearcountry=ceil($allyearscountry/$num);











/***********************************************


			虚拟数据



***********************************************/
//上周   下周删除  7.25删除

	//上月
/*	$firstp=735;
	$secondp=692;
	$thirdp=775;
	$fourthp=756;
*/
if($address=='北京博瑞祥星汽车销售有限公司'){
	$nextone=strtotime('2016-7-25');
	if(time()<$nextone){
		//上周   下周删除  7.25删除
		$onep=201;
		$twop=197;
		$threep=186;
		$fourp=199;
		$fivep=204;
	}
	$nextmonth=strtotime('2016-9-1');
	if(time()<$nextmonth){
		//上月
		$firstp=1011;
		$secondp=1209;
		$thirdp=1102;
		$fourthp=1001;
	}
	$time=date('Ym',time());
	if($time=='201607'){
		$firstjk=1062;
		$secondjk=1190;
	}

	$shijian=date('Y',time());
	if($shijian=='2016'){
		$firstmonth=7750;
		$secondmonth=8213;
		$thirdmonth+=2252;
		$thirdmonth-=$bak;
	}
	if($time=='201607'){
		$month+=$month*2;
		$avgmonth+=$avgmonth*2;
	}
	if($shijian=='2016'){
		$years+=$years*10;
		$avgyears+=$avgyears*10;
		$monthcountry+=$monthcountry*2;
		$yearcountry+=$yearcountry*10;
	}
}else if($address=="义乌市博奥汽车销售服务有限公司"){
	$nextone=strtotime('2016-8-1');
	if(time()<$nextone){
		//上周   下周删除  7.25删除
		$onep=111;
		$twop=97;
		$threep=89;
		$fourp=102;
		$fivep=113;
		$sixp=108;
		$sevenp=112;
	}
	$nextmonth=strtotime('2016-9-1');
	if(time()<$nextmonth){
		//上月
		$firstp=672;
		$secondp=701;
		$thirdp=689;
		$fourthp=732;
	}
	$ts=time();
	if($one<1469158943){
		$onejk=121;
	}
	$time=date('Ym',time());
	if($time=='201607'){
		$firstjk=462;
		$secondjk=510;
	}

	$shijian=date('Y',time());
	if($shijian=='2016'){
		$firstmonth=2519;
		$secondmonth=3751;
		$thirdmonth+=972;
		$thirdmonth-=$bak;
	}
	if($time=='201607'){
		$month+=$month*2;
		$avgmonth+=$avgmonth*2;
	}
	if($shijian=='2016'){
		$years+=$years*10;
		$avgyears+=$avgyears*10;
		$monthcountry+=$monthcountry*2;
		$yearcountry+=$yearcountry*10;
	}
}else if($address=='广州粤奥汽车销售服务有限公司'){
	$nextone=strtotime('2016-7-25');
	if(time()<$nextone){
		//上周   下周删除  7.25删除
		$onep=201;
		$twop=197;
		$threep=186;
		$fourp=199;
		$fivep=204;
	}
	$nextmonth=strtotime('2016-9-1');
	if(time()<$nextmonth){
		//上月
		$firstp=1011;
		$secondp=1209;
		$thirdp=1102;
		$fourthp=1001;
	}
	$time=date('Ym',time());
	if($time=='201607'){
		$firstjk=1062;
		$secondjk=1190;
	}

	$shijian=date('Y',time());
	if($shijian=='2016'){
		$firstmonth=6292;
		$secondmonth=7040;
		$thirdmonth+=2252;
		$thirdmonth-=$bak;
	}
	if($time=='201607'){
		$month+=$month*2;
		$avgmonth+=$avgmonth*2;
	}
	if($shijian=='2016'){
		$years+=$years*10;
		$avgyears+=$avgyears*10;
		$monthcountry+=$monthcountry*2;
		$yearcountry+=$yearcountry*10;
	}
}else if($address=='辽宁鑫迪汽车销售服务有限公司'){
	$nextone=strtotime('2016-8-1');
	if(time()<$nextone){
		//上周   下周删除  7.25删除
		$onep=501;
		$twop=497;
		$threep=489;
		$fourp=502;
		$fivep=413;
		$sixp=408;
		$sevenp=512;
	}
	$nextmonth=strtotime('2016-9-1');
	if(time()<$nextmonth){
		//上月
		$firstp=3172;
		$secondp=3001;
		$thirdp=2989;
		$fourthp=2732;
	}
	$time=date('Ym',time());
	if($time=='201607'){
		$firstjk=4201;
		$secondjk=3190;
	}

	$shijian=date('Y',time());
	if($shijian=='2016'){
		$firstmonth=25105;
		$secondmonth=36682;
		$thirdmonth+=7391;
		$thirdmonth-=$bak;
	}
	if($time=='201607'){
		$month+=$month*2;
		$avgmonth+=$avgmonth*2;
	}
	if($shijian=='2016'){
		$years+=$years*10;
		$avgyears+=$avgyears*10;
		$monthcountry+=$monthcountry*2;
		$yearcountry+=$yearcountry*10;
	}
}else if($address=='江苏天奥汽车销售服务有限公司'){
	$nextone=strtotime('2016-8-1');
	if(time()<$nextone){
		//上周   下周删除  7.25删除
		$onep=201;
		$twop=297;
		$threep=189;
		$fourp=202;
		$fivep=213;
		$sixp=208;
		$sevenp=212;
	}
	$nextmonth=strtotime('2016-9-1');
	if(time()<$nextmonth){
		//上月
		$firstp=989;
		$secondp=1001;
		$thirdp=919;
		$fourthp=832;
	}
	$ts=time();
	if($one<1469158943){
		$onejk=121;
	}
	$time=date('Ym',time());
	if($time=='201607'){
		$firstjk=1102;
		$secondjk=1304;
		$thirdjk+=121;
	}

	$shijian=date('Y',time());
	if($shijian=='2016'){
		$firstmonth=5991;
		$secondmonth=7913;
		$thirdmonth+=2406;
		$thirdmonth-=$bak;
	}
	if($time=='201607'){
		$month+=$month*2;
		$avgmonth+=$avgmonth*2;
	}
	if($shijian=='2016'){
		$years+=$years*10;
		$avgyears+=$avgyears*10;
		$monthcountry+=$monthcountry*2;
		$yearcountry+=$yearcountry*10;
	}
}else if($address=='成都新元素雅麓汽车销售服务有限公司'){
	$nextone=strtotime('2016-8-1');
	if(time()<$nextone){
		//上周   下周删除  7.25删除
		$onep=101;
		$twop=127;
		$threep=109;
		$fourp=102;
		$fivep=113;
		$sixp=108;
		$sevenp=112;
	}
	$nextmonth=strtotime('2016-9-1');
	if(time()<$nextmonth){
		//上月
		$firstp=689;
		$secondp=701;
		$thirdp=719;
		$fourthp=632;
	}
	$time=date('Ym',time());
	if($time=='201607'){
		$firstjk=720;
		$secondjk=812;
	}
	
	$shijian=date('Y',time());

	if($shijian=='2016'){
		$firstmonth=8447;
		$secondmonth=9371;
		$thirdmonth+=1532;
		$thirdmonth-=$bak;
	}
	if($time=='201607'){
		$month+=$month*2;
		$avgmonth+=$avgmonth*2;
	}
	if($shijian=='2016'){
		$years+=$years*10;
		$avgyears+=$avgyears*10;
		$monthcountry+=$monthcountry*2;
		$yearcountry+=$yearcountry*10;
	}
}else if($address=='云南驰泰汽车销售服务有限公司'){
	$nextone=strtotime('2016-8-1');
	if(time()<$nextone){
		//上周   下周删除  7.25删除
		$onep=201;
		$twop=297;
		$threep=189;
		$fourp=202;
		$fivep=213;
		$sixp=208;
		$sevenp=212;
	}
	$nextmonth=strtotime('2016-9-1');
	if(time()<$nextmonth){
		//上月
		$firstp=989;
		$secondp=1001;
		$thirdp=919;
		$fourthp=832;
	}
	$ts=time();
	if($one<1469158943){
		$onejk=121;
	}
	$time=date('Ym',time());
	if($time=='201607'){
		$firstjk=921;
		$secondjk=1098;
		$thirdjk+=121;
	}

	$shijian=date('Y',time());
	if($shijian=='2016'){
		$firstmonth=12350;
		$secondmonth=13796;
		$thirdmonth+=2140;
		$thirdmonth-=$bak;
	}
	if($time=='201607'){
		$month+=$month*2;
		$avgmonth+=$avgmonth*2;
	}
	if($shijian=='2016'){
		$years+=$years*10;
		$avgyears+=$avgyears*10;
		$monthcountry+=$monthcountry*2;
		$yearcountry+=$yearcountry*10;
	}
}else if($address=='宁夏奥立升汽车销售服务有限公司'){
	$nextone=strtotime('2016-8-1');
	if(time()<$nextone){
		//上周   下周删除  7.25删除
		$onep=221;
		$twop=277;
		$threep=219;
		$fourp=232;
		$fivep=203;
		$sixp=218;
		$sevenp=222;
	}
	$nextmonth=strtotime('2016-9-1');
	if(time()<$nextmonth){
		//上月
		$firstp=889;
		$secondp=901;
		$thirdp=819;
		$fourthp=832;
	}
	$time=date('Ym',time());
	if($time=='201607'){
		$firstjk=981;
		$secondjk=1213;
	}

	$shijian=date('Y',time());
	if($shijian=='2016'){
		$firstmonth=12350;
		$secondmonth=14796;
		$thirdmonth+=2194;
		$thirdmonth-=$bak;
	}
	if($time=='201607'){
		$month+=$month*2;
		$avgmonth+=$avgmonth*2;
	}
	if($shijian=='2016'){
		$years+=$years*10;
		$avgyears+=$avgyears*10;
		$monthcountry+=$monthcountry*2;
		$yearcountry+=$yearcountry*10;
	}
}else if($address=="陕西奥诚汽车销售服务有限公司"){
	$nextone=strtotime('2016-8-1');
	if(time()<$nextone){
		//上周   下周删除  7.25删除
		$onep=201;
		$twop=177;
		$threep=201;
		$fourp=242;
		$fivep=183;
		$sixp=204;
		$sevenp=182;
	}
	$nextmonth=strtotime('2016-9-1');
	if(time()<$nextmonth){
		//上月
		$firstp=809;
		$secondp=861;
		$thirdp=719;
		$fourthp=732;
	}
	$time=date('Ym',time());
	if($time=='201607'){
		$firstjk=985;
		$secondjk=1214;
	}

	$shijian=date('Y',time());
	if($shijian=='2016'){
		$firstmonth=8274;
		$secondmonth=12582;
		$thirdmonth+=2199;
		$thirdmonth-=$bak;
	}
	if($time=='201607'){
		$month+=$month*2;
		$avgmonth+=$avgmonth*2;
	}
	if($shijian=='2016'){
		$years+=$years*10;
		$avgyears+=$avgyears*10;
		$monthcountry+=$monthcountry*2;
		$yearcountry+=$yearcountry*10;
	}
}

















require(ROOT . 'view/iwocar5/4S_MarketDirector_Main.html');

 ?>